package com.guanyong.services;

import com.guanyong.constant.VideoConstant;
import com.guanyong.dao.IVideoSourceDaoMapper;
import com.guanyong.model.FilmModel;
import com.guanyong.model.VideoSourceModel;
import com.guanyong.model.VideoTopLogModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/6/2.
 */
@Service
public class VideoSourceService {

    @Autowired
    IVideoSourceDaoMapper iVideoSourceDaoMapper;

    @Autowired
    FilmServices filmServices;

    public Integer UpdateVideoScore(VideoSourceModel videoScorceModel,String objectid){
        return iVideoSourceDaoMapper.update(videoScorceModel);

    }


    public List<VideoSourceModel> GetVideoScorceByObjectId(Integer classType,
                                                           String objectid,
                                                           Integer show){
        if(show==-1){
            return iVideoSourceDaoMapper.selectVideoScorceAll(objectid,classType);
        }else{
            return iVideoSourceDaoMapper.selectVideoScorce(objectid,classType,show);
        }
    }

    public VideoSourceModel GetVideoScorceByObjectIdType(Integer classType, String objectid,Integer fSourcetype){
            return iVideoSourceDaoMapper.selectVideoScorceByType(objectid,classType,fSourcetype);
    }

    public VideoSourceModel GetVideoScorceByObjectIdShow(String objectid){
            return iVideoSourceDaoMapper.getVideoScorce(objectid,0,0);
    }

    public VideoSourceModel selectByPrimaryKey(Integer fid){
        return iVideoSourceDaoMapper.selectByPrimaryKey(fid);
    }
    public Integer UpdateVideoSource(VideoSourceModel videoSourceModel){
        return iVideoSourceDaoMapper.update(videoSourceModel);
    }
    public Integer AddVideoSource(VideoSourceModel videoSourceModel){
        return iVideoSourceDaoMapper.insert(videoSourceModel);
    }

    public HashMap<String,Object> getVideoClipsList(int pno, int pagesize, int allcount) {
        HashMap<String,Object> hashMap=new HashMap();
        if (allcount<0){
            Integer count=iVideoSourceDaoMapper.SelectVideoSourceListCount(VideoConstant.SOURCE_TYPE_CLIPS);
            hashMap.put("count",count);
        }
        else {
            hashMap.put("count",allcount);
        }
        List<VideoSourceModel> videoSourceModellList =iVideoSourceDaoMapper.SelectVideoSourceList
                (VideoConstant.SOURCE_TYPE_CLIPS,(pno-1)*pagesize,pagesize);

        List<Object> list = new ArrayList<Object>();
        for (VideoSourceModel videoSourceModel :videoSourceModellList){
            FilmModel filmModel= filmServices.GetFilmModelById(videoSourceModel.getfObjectid());

            if (filmModel!=null) {
                filmModel.setfSourceurl(videoSourceModel.getfSourceurl());
                list.add(filmModel);
            }
        }
        hashMap.put("list",list);
        return hashMap;
    }
}
